package com.runchinaup.smartbelt.domian;

import android.content.Context;
import android.content.SharedPreferences;

import com.runchinaup.smartbelt.App;

/**
 * Created by liber on 2018/2/5.
 * <p>
 * 来电提醒和短信提醒的包头都是一样的，只是提醒类型不一样。。。
 */

public class PhoneCallAndMessage extends BaseData {

    //头文件
    private byte phoneOne = (byte) 0xa1;
    private byte phoneTwo = (byte) 0x5a;
    private byte phoneThree = (byte) 0x06;
    private byte phoneFour = (byte) 0x03;

    //来电提醒
    private byte phoneCall = 0x08;
    //短信提醒
    private byte phoneMessage = 0x10;

    SharedPreferences shared = App.getApp().getSharedPreferences("buttonIsOpen", Context.MODE_PRIVATE);

    //来电提醒
    public byte[] remindByPhone() {
        boolean loose = shared.getBoolean("isLoose", false);
        byte[] setValue = new byte[]{
                phoneOne,
                phoneTwo,
                phoneThree,
                phoneFour,
                phoneCall,
                (byte) (loose ? 1 : 0),
                0
        };
        setValue[setValue.length - 1] = CountCheckCode(setValue);
        return setValue;
    }

    //短信提醒
    public byte[] remindByMessage() {
        boolean loose = shared.getBoolean("isLoose", false);
        byte[] setValue = new byte[]{
                phoneOne,
                phoneTwo,
                phoneThree,
                phoneFour,
                phoneMessage,
                (byte) (loose ? 1 : 0),
                0
        };
        setValue[setValue.length - 1] = CountCheckCode(setValue);
        return setValue;
    }

    //手机防丢失
    public byte[] remindPhoneLoose() {
        boolean loose = shared.getBoolean("isLoose", false);
        byte[] setValue = new byte[]{
                phoneOne,
                phoneTwo,
                phoneThree,
                phoneFour,
                0,
                (byte) (loose ? 1 : 0),
                0
        };
        setValue[setValue.length - 1] = CountCheckCode(setValue);
        return setValue;
    }


    //关闭手机防丢功能
    public byte[] closePhoneLoose() {
        byte[] setValue = new byte[]{
                phoneOne,
                phoneTwo,
                phoneThree,
                phoneFour,
                0,
                (byte) 0x00,
                0
        };
        setValue[setValue.length - 1] = CountCheckCode(setValue);
        return setValue;
    }

}
